package com.javaclimb.filmbuy.controller;

import com.github.pagehelper.PageInfo;
import com.javaclimb.filmbuy.common.Result;
import com.javaclimb.filmbuy.entity.SeatInfo;
import com.javaclimb.filmbuy.entity.UserInfo;
import com.javaclimb.filmbuy.service.SeatInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* 座位信息的controller层
* */
@RestController
@RequestMapping(value = "/seatInfo")
public class SeatInfoController {
    @Resource
    private SeatInfoService seatInfoService;

    /**
    * 增加或更新一个座位信息
    * */
    @PostMapping
    public Result<SeatInfo> save(@RequestBody SeatInfo seatInfo){
        seatInfoService.save(seatInfo);
        return Result.success(seatInfo);
    }

    /**
    * 根据主键id删除一个座位信息
    * */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id){
        seatInfoService.delete(id);
        return Result.success();
    }

    /**
    * 更新一个座位信息
    * */
    @PutMapping
    public Result<SeatInfo> update(@RequestBody SeatInfo seatInfo) {
        seatInfoService.update(seatInfo);
        return Result.success(seatInfo);
    }

    /**
     * 根据主键id查询一个座位信息
     * */
    @GetMapping("/{id}")
    public Result<SeatInfo> findById(@PathVariable Long id){
        SeatInfo seatInfo = seatInfoService.findById(id);
        return Result.success(seatInfo);
    }
    /**
     *根据电影id查询已售座位
     */
    @GetMapping("/detail")
    public Result<SeatInfo>findDetal(@RequestParam Long goodsId){
        SeatInfo seatInfo = seatInfoService.findDetail(goodsId);
        return Result.success(seatInfo);
    }


    /**
     * 增加一个座位信息
     */
    @PostMapping
    public Result<SeatInfo> add(@RequestBody SeatInfo seatInfo){
        seatInfoService.add(seatInfo);
        return Result.success(seatInfo);
    }
}
